<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>

<body>
    <div id="app">

        <router-link to="/login?id=10&name=cuihui">登录</router-link>
        <router-link to="/register">注册</router-link>
        <!-- 组件显示坑 -->
        <router-view></router-view>
    </div>
    <script>

        // 定义两个组件对象
        var login = {
            template: "<h1>登录--{{$route.query.id}}---{{$route.query.name}}</h1>",
            created() {
                console.log(this.$route.query.id);
                console.log(this.$route.query.name);
            },
        }

        var register = {
            template: "<h1>注册</h1>"
        }

        // 路由对象
        var router = new VueRouter({
            routes: [
                {path: "/login", component:login},
                {path: "/register", component:register}
            ]
        })

        var vm=new Vue({
           el:'#app',
           data:{},
           methods:{},
           router   // 绑定路由,简化写法
        });
    </script>
</body>

</html>